import React from 'react';
import { connect } from 'react-redux';
import { message } from 'antd';
import * as routerActions from 'react-router-redux';
import Api from 'Utils/api';
import Article from '../../Components/SpeakArticle';
import './index.scss';

class GovDetail extends React.PureComponent {
  constructor(props) {
    super(props);

    this.state = {
      title: '',
      createTime: '',
      author: '',
      src: '',
      content: '',
      speakId: props.params.id
    };

    this.getSpeak = ::this.getSpeak;
    this.returnHandle = ::this.returnHandle;
  }
  componentWillMount() {
    this.getSpeak();
  }
  getSpeak() {
    const api = new Api({
      method: 'GET',
      path: `/suggests/user/${this.props.params.id}`,
      success: (json) => {
        this.setState({
          title: json.title,
          createTime: json.create_time,
          favor: json.total_like,
          src: json.type || '',
          content: json.content,
          mediaType: json.media_type || ''
        });
      },
      error: (msg) => {
        message.error(msg);
      }
    });
    api.run();
  }
  returnHandle() {
    this.props.dispatch(routerActions.goBack());
  }
  render() {
    const { title, createTime, author, content, favor, src, mediaType, speakId } = this.state;
    return (
      <div className="work-report-wrap">
        <Article
          title={title}
          createTime={createTime}
          author={author}
          content={content}
          favor={favor}
          videosrc={src}
          mediaType={mediaType}
          speakId={speakId}
        />
      </div>
    );
  }
}

function mapStateToProps(state) {
  return {
    ...state.routing,
  };
}
export default connect(mapStateToProps)(GovDetail);
